---
id: datavalidator
title: 3. DataValidator 静态类
sidebar_label: 3. DataValidator 静态类
---

## 3.1 验证对象数据

```cs
var result = DataValidator.TryValidateObject(obj);
```

## 3.2 验证单个值

```cs
var result = DataValidator.TryValidateValue(value, typeof(RequiredAttribure), typeof(RangeAttribute));
```

## 3.3 正则表达式验证单个值

```cs
var result = DataValidator.TryValidateValue(value,"正则表达式");
```

## 3.4 验证类型验证单个值

```cs
var result = DataValidator.TryValidateValue(value, ValidationTypes.Number);

var result2 = DataValidator.TryValidateValue(value, ValidationPattern.AllOfThem, ValidationTypes.Number, ValidationTypes.Required);
```
